#include <iostream>
#include <cstring>

using namespace std;
const int N = 35;
int a[N][N];
bool st[N][N];
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
int n, m;
void dfs(int i, int j)
{
    st[i][j] = true;
    for (int k = 0; k < 4; k++)
    {
        int x = i + dx[k], y = dy[k] + j;
        if(x >= 0 && x <= n + 1 && y >= 0 && y <= n + 1 && st[x][y] == false && a[x][y] == 0)
        {
            dfs(x, y);
        }
    }
}
int main()
{
    while (cin >> n)
    {
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= n; j++)
            {
                cin >> a[i][j];
            }
        }

        dfs(0, 0);
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= n; j++)
            {
                if (a[i][j])
                    cout << a[i][j] << " ";
                else if (st[i][j])
                    cout << 0 << " ";
                else
                    cout << 2 << " ";
            }
            cout << endl;
        }
    }
    return 0;
}